import request from '@/utils/request'
import type {
  LoginData,
  LoginResponseData,
  PhoneCode,
  WXLoginResponseData,
} from './type'

enum API {
  // 获取短信验证码的接口地址
  USER_CODE_URL = '/sms/send/',
  // 用户登录的接口地址
  USER_LOGIN_URL = '/user/login',
  // 获取微信扫码登录需要的参数
  WX_LOGIN_URL = '/user/weixin/getLoginParam/',
}

// 获取手机验证码的接口方法
export const reqPhoneCode = (tel: string) =>
  request.get<any, PhoneCode>(API.USER_CODE_URL + tel)
// 用户登录的接口方法
export const reqUserLogin = (data: LoginData) =>
  request.post<any, LoginResponseData>(API.USER_LOGIN_URL, data)
// 获取生成微信扫码登录二维码需要参数的接口方法
export const reqWxLogin = (wxRedirectUri: string) =>
  request.get<any, WXLoginResponseData>(
    API.WX_LOGIN_URL + `?wxRedirectUri=${wxRedirectUri}`,
  )
